async function routes (fastify, options) {
    const db = fastify.mongo.db;

    fastify.get('/', async (request, reply) => {
      return { hello: 'world' }
    })
     
    // 插入mongoDB
    fastify.get('/mongoDB/add', async (request, reply) => {
      const collection = db.collection('test_collection');
      await collection.insertMany([
        {
          subject: "为什么Fastify这么快？",
          datetime: Date.now(),
          state: 0,
        },
        {
          subject: "插入文档",
          datetime: Date.now(),
          state: 1,
        },
        {
          subject: "更新文档",
          datetime: Date.now(),
          state: 0,
        },
        {
          subject: "删除文档",
          datetime: Date.now(),
          state: 0,
        },
      ]);
      return { error: "", errorCode: 0, result: {} };
    });

    // 插入mysql
    fastify.get("/mysql/insert", async (req, reply) => {
      fastify.mysql.getConnection((err, connection) => {
        connection.execute(
          `CREATE TABLE IF NOT EXISTS runoob_tbl (
            runoob_id INT UNSIGNED AUTO_INCREMENT,
            runoob_title VARCHAR(100) NOT NULL,
            runoob_author VARCHAR(40) NOT NULL,
            submission_date datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
            PRIMARY KEY ( runoob_id )
         )ENGINE=InnoDB DEFAULT CHARSET=utf8;`,
          (err, result, fields) => {
          
            connection.execute(
              `INSERT INTO runoob_tbl (runoob_title, runoob_author) VALUES ('mysql', '${req.query.author? req.query.author : 'defalut'}')`,
              (err, result, fields) => {
                console.log();
                return reply
                  .code(200)
                  .header("Content-Type", "application/json; charset=utf-8")
                  .send({ result });
              }
            );
          } 
        );
      });
    });
    // 存储redis
    fastify.get("/redis/set", async (request, reply) => {
      if (!request.query)
        return { error: "401", errorCode: "param key is required" };
      const { redis } = fastify;
      Object.keys(request.query).forEach((key) => {
        redis.set(key, request.query[key]);
      });
      return { error: "", errorCode: 0, result: request.query };
    });
    // 获取redis
    fastify.get("/redis/get/:key", async (request, reply) => {
      if (!request.params.key)
        return { error: "401", errorCode: "param key is required" };
      const { redis } = fastify;
      let val = await redis.get(request.params.key);
      return { error: "", errorCode: 0, result: val };
    });

    // Elasticsearch 存储
    fastify.get("/es/add", async (request, reply) => {
      let result = await fastify.elastic.index({
        index: "todos", //相当于database
        body: {
          //文档到内容
          subject: "tiger is a danger animal",
          datetime: Date.now(),
          state: 0,
        },
      });
      return result;
    });
    // Elasticsearch 获取
    fastify.get("/es/get", async (request, reply) => {
      let result = await fastify.elastic.search({
        index: "todos",
        type: "todos",
        body: {
          query: {
            match: {
              state: 0,
            },
          },
        },
      });
      return result;
    });
  }
  
  module.exports = routes

  